<!DOCTYPE HTML>
<!--
	Dimension by HTML5 UP
	html5up.net | @ajlkn
	Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
 <head>
  <title>
   Dimension by HTML5 UP
  </title>
  <!-- <meta charset="utf-8" /> -->
  <!-- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> -->
  <meta charset="utf-8"/>
  <meta content="width=device-width,initial-scale=1.0" name="viewport"/>
  <link href="../../assets/css/article.css" rel="stylesheet"/>
  <link href="https://cdn.bootcss.com/highlight.js/9.15.8/styles/github.min.css" rel="stylesheet"/>
  <noscript>
   <link href="../../assets/css/noscript.css" rel="stylesheet"/>
  </noscript>
 </head>
 <body>
  <div id="app">
  </div>
  <!-- built files will be auto injected -->
 </body>
 <body class="is-preload">
  <!-- Wrapper -->
  <div id="wrapper">
   <!-- Main -->
   <div id="main">
    <article id="article">
     <h1 id="nginx">
      nginx 使用记录
     </h1>
     <hr/>
     <h2 id="_1">
      安装
     </h2>
     <h3 id="linux">
      Linux软件安装
     </h3>
     <div class="codehilite">
      <pre><span></span><code>yum install -y pcre
yum install -y pcre-devel
yum install -y openssl-devel
yum install -y epel-release
yum install -y nginx
</code></pre>
     </div>
     <h3 id="dockerlinuxwindows">
      docker安装（linux，Windows）
     </h3>
     <p>
      教程链接：https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-docker/#running-nginx-plus-in-a-docker-container
     </p>
     <h3 id="_2">
      访问权限问题
     </h3>
     <div class="codehilite">
      <pre><span></span><code><span class="k">user</span> <span class="n">root</span>

<span class="n">chmod</span> <span class="n">a</span><span class="o">+</span><span class="n">x</span> <span class="n">xxxx</span>
</code></pre>
     </div>
     <h3 id="_3">
      配置不同路径访问不同的静态文件
     </h3>
     <p>
      好像只能存在一个roo，另一个需要使用alias，例子如下：
     </p>
     <div class="codehilite">
      <pre><span></span><code><span class="n">server</span> <span class="err">{</span>
        <span class="k">listen</span>       <span class="mi">80</span> <span class="n">default_server</span><span class="p">;</span>
        <span class="k">listen</span>       <span class="p">[::]:</span><span class="mi">80</span> <span class="n">default_server</span><span class="p">;</span>
        <span class="k">server_name</span>  <span class="n">_</span><span class="p">;</span>
        <span class="o">#</span><span class="n">root</span>         <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="k">share</span><span class="o">/</span><span class="n">nginx</span><span class="o">/</span><span class="n">html</span><span class="p">;</span>

        <span class="o">#</span><span class="n">websocket</span>
        <span class="k">map</span> <span class="err">$</span><span class="n">http_upgrade</span> <span class="err">$</span><span class="n">connection_upgrade</span> <span class="err">{</span>
            <span class="k">default</span> <span class="n">upgrade</span><span class="p">;</span>
            <span class="s1">''</span> <span class="k">close</span><span class="p">;</span>
        <span class="err">}</span>

        <span class="o">#</span> <span class="k">Load</span> <span class="n">configuration</span> <span class="n">files</span> <span class="k">for</span> <span class="n">the</span> <span class="k">default</span> <span class="n">server</span> <span class="n">block</span><span class="p">.</span>
        <span class="n">include</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">nginx</span><span class="o">/</span><span class="k">default</span><span class="p">.</span><span class="n">d</span><span class="cm">/*.conf;</span>

<span class="cm">        root /root/projects/dist;</span>
<span class="cm">        #index  index.html index.htm index.php;</span>

<span class="cm">        location / {</span>
<span class="cm">            root /root/projects/dist;</span>
<span class="cm">            index index.html;</span>
<span class="cm">        }</span>

<span class="cm">        location /nssas {</span>
<span class="cm">            alias /usr/share/nginx/html/;</span>
<span class="cm">            index index.html;</span>
<span class="cm">        }</span>
<span class="cm">}</span>
</code></pre>
     </div>
     <h3 id="_4">
      文件服务器搭建
     </h3>
     <p>
      进行location的配置即可，如下面的配置的话就是访问：/home/download/download,根据情况进行修改即可
     </p>
     <div class="codehilite">
      <pre><span></span><code>location /download <span class="o">{</span>
    root /home/download<span class="p">;</span>
    autoindex on<span class="p">;</span>
    autoindex_exact_size on<span class="p">;</span>
    autoindex_localtime on<span class="p">;</span>
<span class="o">}</span>
</code></pre>
     </div>
     <h3 id="_5">
      配置示例
     </h3>
     <div class="codehilite">
      <pre><span></span><code>    <span class="nt">server</span> <span class="p">{</span>
        <span class="err">listen</span>       <span class="err">80</span> <span class="err">default_server</span><span class="p">;</span>
        <span class="n">listen</span>       <span class="cp">[</span><span class="p">::</span><span class="cp">]</span><span class="p">:</span><span class="mi">80</span> <span class="n">default_server</span><span class="p">;</span>
        <span class="err">server_name</span>  <span class="err">_</span><span class="p">;</span>
        <span class="err">#root</span>         <span class="err">/usr/share/nginx/html</span><span class="p">;</span>
        <span class="err">root</span>         <span class="err">/home</span><span class="p">;</span>

        <span class="err">#websocket</span>
        <span class="err">#map</span> <span class="err">$http_upgrade</span> <span class="err">$connection_upgrade</span> <span class="err">{</span>
        <span class="err">#</span>    <span class="err">default</span> <span class="err">upgrade</span><span class="p">;</span>
        <span class="err">#</span>    <span class="err">''</span> <span class="err">close</span><span class="p">;</span>
        <span class="err">#</span><span class="p">}</span>

        <span class="err">#</span> <span class="nt">Load</span> <span class="nt">configuration</span> <span class="nt">files</span> <span class="nt">for</span> <span class="nt">the</span> <span class="nt">default</span> <span class="nt">server</span> <span class="nt">block</span><span class="o">.</span>
        <span class="nt">include</span> <span class="o">/</span><span class="nt">etc</span><span class="o">/</span><span class="nt">nginx</span><span class="o">/</span><span class="nt">default</span><span class="p">.</span><span class="nc">d</span><span class="o">/*</span><span class="p">.</span><span class="nc">conf</span><span class="o">;</span>

        <span class="err">#</span> <span class="nt">转</span><span class="err">�</span><span class="o">~</span><span class="nt">O</span><span class="o">~</span><span class="nt">Qwebsocket</span><span class="err">�</span><span class="o">~</span><span class="err">\</span><span class="o">~@</span><span class="err">��</span><span class="o">~</span><span class="nt">A</span><span class="err">�</span><span class="o">~</span><span class="nt">Z</span><span class="o">~</span><span class="nt">D设置</span>
        <span class="nt">proxy_set_header</span> <span class="nt">X-Real_IP</span> <span class="o">$</span><span class="nt">remote_addr</span><span class="o">;</span>
        <span class="nt">proxy_set_header</span> <span class="nt">Host</span> <span class="o">$</span><span class="nt">host</span><span class="o">;</span>
        <span class="nt">proxy_set_header</span> <span class="nt">X_Forward_For</span> <span class="o">$</span><span class="nt">proxy_add_x_forwarded_for</span><span class="o">;</span>
        <span class="nt">proxy_http_version</span> <span class="nt">1</span><span class="p">.</span><span class="nc">1</span><span class="o">;</span>
        <span class="nt">proxy_set_header</span> <span class="nt">Upgrade</span> <span class="o">$</span><span class="nt">http_upgrade</span><span class="o">;</span>
        <span class="nt">proxy_set_header</span> <span class="nt">Connection</span> <span class="s1">'upgrade'</span><span class="o">;</span>

        <span class="nt">location</span> <span class="o">/</span> <span class="p">{</span>
            <span class="err">autoindex</span> <span class="err">on</span><span class="p">;</span>
            <span class="err">autoindex_exact_size</span> <span class="err">on</span><span class="p">;</span>
            <span class="err">autoindex_localtime</span> <span class="err">on</span><span class="p">;</span>
        <span class="p">}</span>

        <span class="nt">location</span> <span class="o">/</span><span class="nt">xxx</span> <span class="p">{</span>
            <span class="err">proxy_pass</span> <span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="o">:</span><span class="mi">8188</span><span class="o">/</span><span class="n">xxx</span><span class="p">;</span>
        <span class="p">}</span>

        <span class="nt">error_page</span> <span class="nt">404</span> <span class="o">/</span><span class="nt">404</span><span class="p">.</span><span class="nc">html</span><span class="o">;</span>
            <span class="nt">location</span> <span class="o">=</span> <span class="o">/</span><span class="nt">40x</span><span class="p">.</span><span class="nc">html</span> <span class="p">{</span>
        <span class="p">}</span>

        <span class="nt">error_page</span> <span class="nt">500</span> <span class="nt">502</span> <span class="nt">503</span> <span class="nt">504</span> <span class="o">/</span><span class="nt">50x</span><span class="p">.</span><span class="nc">html</span><span class="o">;</span>
            <span class="nt">location</span> <span class="o">=</span> <span class="o">/</span><span class="nt">50x</span><span class="p">.</span><span class="nc">html</span> <span class="p">{</span>
        <span class="p">}</span>
    <span class="err">}</span>
</code></pre>
     </div>
     <h2 id="_6">
      参考链接
     </h2>
     <ul>
      <li>
       <a href="https://www.jb51.net/article/99305.htm">
        nginx配置访问图片路径以及html静态页面的调取方法
       </a>
      </li>
      <li>
       <a href="https://www.jianshu.com/p/e0dadb871894">
        nginx 403 Forbidden 排错记录
       </a>
      </li>
      <li>
       <a href="https://www.jianshu.com/p/a195c2f42e15">
        Nginx安装配置
       </a>
      </li>
      <li>
       <a href="https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7">
        How To Install Nginx on CentOS 7
       </a>
      </li>
      <li>
       <a href="https://www.jianshu.com/p/a9363379f23b">
        利用nginx搭建小型的文件服务器
       </a>
      </li>
      <li>
       <a href="https://blog.csdn.net/bruce128/article/details/9665503">
        snginx修改上传文件大小限制
       </a>
      </li>
     </ul>
    </article>
   </div>
   <!-- Footer -->
   <footer id="footer">
    <p class="copyright">
     © Untitled. Design:
     <a href="https://html5up.net">
      HTML5 UP
     </a>
     .
    </p>
   </footer>
  </div>
  <!-- BG -->
  <div id="bg">
  </div>
  <!-- Scripts -->
  <script src="../assets/js/jquery.min.js">
  </script>
  <script src="../assets/js/browser.min.js">
  </script>
  <script src="../assets/js/breakpoints.min.js">
  </script>
  <script src="../assets/js/util.js">
  </script>
  <script src="../assets/js/main.js">
  </script>
 </body>
</html>
